import { login } from "../../../api/User.js";

const oFoms = document.forms[1];
const oBtns = oFoms.querySelectorAll(".btn");
const oLis = document.querySelectorAll(".list li");
const oUser = document.querySelector("#username");
const oPwd = document.querySelector("#pwd");
const oPhone = document.querySelector("#phone");
const oCc = document.querySelector("#checkCode");
oBtns[0].onclick = function () {
  location.href = "../reg/reg.html";
};

oBtns[1].onclick = function () {
  const User = {
    uname: oFoms.uname.value,
    upwd: oFoms.upwd.value,
  };
  console.log(User);
  login(User).then(function (res) {
    const {
      data: { code, msg, data },
    } = res;

    if (code) {
      sessionStorage.User = JSON.stringify(data);
      location.href = "../index/index.html";
      return false;
    }
    if (!code) {
      alert(msg);
    }
  });
  return false;
};

oLis.forEach((item, index) => {
  item.onclick = function () {
    oLis.forEach((item) => {
      item.className = "";
    });
    this.className = "active";
    oUser.className = index == 0 ? "dis-n select" : "dis-n";
    oPwd.className = index == 0 ? "dis-n select" : "dis-n";
    oPhone.className = index == 1 ? "dis-n select" : "dis-n";
    oCc.className = index == 1 ? "dis-n select" : "dis-n";
   
  };
});
